<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models\Adminer;

use Carbon\Carbon;
use App\Models\Eloquent;

/**
 * Class Role
 * 
 * @property int $id
 * @property string $name
 * @property string $remark
 * @property int $enable
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 *
 * @package App\Models
 */
class Role extends Eloquent
{
	protected $table = 'role';

	protected $casts = [
		'enable' => 'int'
	];

	protected $fillable = [
		'name',
		'remark',
		'enable'
	];

    public static function getByStoreId($name, ...$cols)
    {
        $query = self::select(...$cols);

        if($name) {
            $query->where('name', 'like', '%'. $name. '%');
        }

        return $query->get();
    }

    public function label() {
        $this->menus = Menus::getMenusByRoleId($this->id);
        return $this;
    }

    public static function getByName(string $name)
    {
        return self::where('name', $name)->first();
    }
}
